package cn.neusoft.yuejian307.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.neusoft.yuejian307.R;
import cn.neusoft.yuejian307.activity.VideoDetail;
import cn.neusoft.yuejian307.bean.Video;

import static cn.neusoft.yuejian307.GloableVirable.IMG_URL;



public class VideoAdapter extends  RecyclerView.Adapter< RecyclerView.ViewHolder> {
    private Context mContext;
    private List<Video.ClubvideolistBean> mList;
    public LayoutInflater mLayoutInflater;

    public VideoAdapter(Context mContext, List<Video.ClubvideolistBean> List) {
        this.mContext = mContext;
        this.mList = List;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_video, parent, false);
        VideoAdapter.ViewHolder v = new VideoAdapter.ViewHolder(view);

        return v;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Video.ClubvideolistBean club = (Video.ClubvideolistBean) mList.get(position);
        if (null == club)
            return;
        VideoAdapter.ViewHolder viewHolder = (VideoAdapter.ViewHolder) holder;
        viewHolder.name.setText(club.getVideo_name());
        viewHolder.number.setText(club.getVideo_id());
        if(club.getVideo_pic()!=null) {
            Picasso.with(mContext).load(IMG_URL+club.getVideo_pic()).into(viewHolder.imageView3);
        }
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, VideoDetail.class);
             //   bundle.putInt("id",club.getClub_id());
                intent.putExtra("address",club.getVideo_address());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView name,number;
        ImageView imageView3;

        public ViewHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.name);
            number = (TextView) itemView.findViewById(R.id.number);
            imageView3 = (ImageView) itemView.findViewById(R.id.imageView3);

        }
    }
}
